import { hp } from '@/utils/util'

const SERVER_PATH = process.env.NUXT_SERVER_PATH
const SERVER_PORT = process.env.NUXT_SERVER_PORT
const BASEURL = SERVER_PATH === 'localhost' ? `http://${SERVER_PATH}:${SERVER_PORT}` : ''

export default $axios => auth => ({

  updateNewUserPassword (params) {
    return $axios.$post(`${BASEURL}${auth}/resetPassword`, hp(params))
  },

  getRolesByPage (pageNum, pageSize, params) {
    return $axios.$post(`${BASEURL}${auth}/role/search?pageNum=${pageNum}&pageSize=${pageSize}`, hp(params))
  },

  getRoles () {
    return $axios.$post(`${BASEURL}${auth}/role/searchAll?`)
  },

  addRole (params) {
    return $axios.$post(`${BASEURL}${auth}/role`, hp(params))
  },

  updateRole (id, params) {
    return $axios.$put(`${BASEURL}${auth}/role/${id}`, hp(params))
  },

  delRole (id) {
    return $axios.$delete(`${BASEURL}${auth}/role/${id}`)
  },

  updateUser (id, params) {
    return $axios.$put(`${BASEURL}${auth}/user/${id}`, hp(params))
  },

  delUser (id) {
    return $axios.$delete(`${BASEURL}${auth}/user/${id}`)
  },

  toggleUser (param) {
    return $axios.$post(`${BASEURL}${auth}/user/toggle`, hp(param))
  },

  getPermissions (params) {
    return $axios.$get(`${BASEURL}${auth}/getPermissions`, hp(params))
  },

  getUserByPages (pageNum, pageSize, params) {
    return $axios.$post(`${BASEURL}${auth}/search?pageNum=${pageNum}&pageSize=${pageSize}`, hp(params))
  }
})
